package ro.cityprojects.adminloc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ro.cityprojects.adminloc.entities.Street;
import ro.cityprojects.adminloc.exceptions.ValidationException;
import ro.cityprojects.adminloc.service.StreetService;

/**
 * StreetsController class
 *
 * @author bogdan.solga
 *
 * Date: 02.09.2013, time: 08:52
 */
@Controller
@RequestMapping(value = "/streets")
public class StreetsController extends BaseController<Integer, Street> {

    @Autowired
    private StreetService streetService;

    @Override
    public void save(Street street) throws ValidationException {
        streetService.checkExisting(street);
        streetService.save(street);
    }

    @Override
    public String get(@PathVariable Integer primaryKey, @RequestParam(required = false) String includedFields) {
        return streetService.get(primaryKey, includedFields);
    }

    @Override
    public String get(@RequestParam(required = false) String name, @RequestParam(required = false) String value,
                      @RequestParam(required = false) String includedFields) {
        return streetService.getAll(name, value, includedFields);
    }

    @Override
    public void update(Street street, Integer primaryKey) {
        streetService.update(street, primaryKey);
    }

    @Override
    public void delete(Integer primaryKey) {
        streetService.delete(primaryKey);
    }

    @Override
    public String getMetadata() {
        return streetService.getMetadata();
    }
}
